#ifndef _FENGINE_MESH_OBJECT_
#define _FENGINE_MESH_OBJECT_

#include <vector>
#include "CoreEngine.h"
#include "FEngineType.h"
#include "Node.h"
#include "AABB.h"

namespace FEngine
{
	/**
	 * Load a mesh from a .x file and draw it.
	 */
	class Entity : public Node
	{

		public:
			
			/**
			 * Constructor.
			 * @param _fileName Name of the .x file of the mesh.
			 * @param _textureName Name of the texture file of the mesh.
			 */
			Entity(const std::string& _fileName, const std::string& _textureName);
			/**
			 * Constructor.
			 * @param _fileName Name of the .x file of the mesh.
			 * @param _texture Texture of the mesh.
			 */
			Entity(const std::string& _fileName, LPDIRECT3DTEXTURE9 _texture);
			virtual ~Entity();

			/**
			 * Return the base AABB, without rotation.
			 * @return AABB of the entity.
			 */
			AABB* getAABB() const;

			virtual void update(double _elapsedTime);
			virtual void render(double _elapsedTime);

			
		protected:

			LPDIRECT3DVERTEXBUFFER9			mVertexBuffer;
			IDirect3DVertexDeclaration9*	mVertexDeclaration;
			LPDIRECT3DINDEXBUFFER9			mIndexBuffer;
			
			int								mNumberVertices;
			int								mNumberPrimitives;

			std::string						mMeshFileName;
			LPDIRECT3DTEXTURE9				mMeshTexture;
			bool							mIsTexturePreLoaded;	// Indicate if the texture was already loaded at the creation

			AABB*							mBaseAABB;				// AABB of the original mesh, without transformation
			

			virtual void _createGeometry();
			void _loadTexture(const std::string& _textureName);
	};

} // namespace FEngine

#endif
